#define _CRT_SECURE_NO_WARNINGS
#include"test.h"
void QueueInit(Queue* pq)
{
	assert(pq);
	pq->tou = pq->wei = NULL;
	pq->size = 0;
}
void QueueDestroy(Queue* pq)
{
	assert(pq);
	QNode* p1 = pq->tou;
	while (p1)
	{
		QNode* p2 = p1->next;
		free(p1);
		p1 = p2;
	}
	pq->tou = pq->wei = NULL;
	pq->size = 0;
}
void QueuePush(Queue* pq, leixing x)
{
	assert(pq);
	QNode* p1 = (QNode*)malloc(sizeof(QNode));
	if (p1==NULL)
	{
		perror("malloc p1");
		return 0;
	}
	p1->val = x;
	p1->next = NULL;
	if (pq->tou==NULL)
	{
		pq->tou = pq->wei = p1;
	}
	else
	{
		pq->wei->next = p1;
		pq->wei = p1;
	}
	pq->size++;
}
void QueuePop(Queue* pq)
{
	assert(pq);
	assert(pq->size > 0);
	
	if (pq->tou == pq->wei)
	{
		free(pq->tou);
		pq->tou = pq->wei = NULL;
	}
	else
	{
		QNode* p1 = pq->tou->next;
		free(pq->tou);
		pq->tou = p1;
	}
	pq->size--;
}
leixing QueueFront(Queue* pq)
{
	assert(pq);
	//assert(pq->size > 0);
	assert(pq->tou);
	return pq->tou->val;
}
leixing QueueBack(Queue* pq)
{
	assert(pq);
	//assert(pq->size > 0);
	assert(pq->wei);
	return pq->wei->val;
}

bool QueueEmpty(Queue* pq)
{
	assert(pq);
	return pq->size == 0;
}
int QueueSize(Queue* pq)
{
	assert(pq);
	return pq->size;
}